package com.evola.rm.model
{
	import com.evola.rm.view.project.ProjectModel;

	[Bindable]
	public class ResourceKey
	{

		public var expression:String;
		public var chain:Array;

		public var model:ProjectModel;

		public function ResourceKey()
		{
		}

		public static function create(exp:String, model : ProjectModel):ResourceKey
		{

			var parts:Array=exp.split(".");

			var key:ResourceKey=new ResourceKey();
			key.expression=exp;
			key.chain=parts;
			key.model = model;

			return key;
		}

		public function copy():ResourceKey
		{

			var key:ResourceKey=new ResourceKey();
			key.expression=expression;
			//key.chain = chain.
			key.model = model;

			return key;
		}

		public function get displayLabel():String
		{

			//tekst nam je npr. GlobalFields.entity.name
			var dn:String="";

			var alias:Alias=model.project.getAliasStarting(expression);

			if (alias)
			{
				dn="<font color=\"#" + alias.color.toString(16) + "\"><b>" + alias.name + "</b></font>";
				dn+=expression.substr(alias.code.length);
			}
			else
			{
				dn=expression;
			}

			return dn;
		}

	}
}
